<template>
	<view class="my-content page">
		<view class="search">
			<u-search v-model="keyword" :show-action="false" :placeholder="$t('根据关键字进行搜索')" @search="search"></u-search>
		</view>
		<view class="bidding_news">
			<CandrNewsListItem :item="i" v-for="i in sotreData1" :key="i.id" @click.native="details(i)"
				@communicates="communicates" @communicate="communicate" @userPage="userPage"></CandrNewsListItem>
		</view>
		<Service />
	</view>
</template>

<script>
	import {
		createC2CConversation,
		ImageUrl,
		isBase64,
		time
	} from "@/common/public";
	import {
		IMAGE_URL
	} from "@/config/app";
	import Service from '@/components/service/service.vue'
	import CandrNewsListItem from "@/components/detail/CandrNewsListItem.vue";

	export default {
		components: {
			Service,
			CandrNewsListItem
		},
		data() {
			return {
				sotreData1: [],
				isData: [],
				keyword: "",
				type: 1,
				page: 1
			};
		},
		onLoad({
			type
		}) {
			this.type = type
			console.log(type)
			this.GoodsList({
				type,
				page: this.page,
				keyword: this.keyword
			})
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t("中俄新闻列表")
			})
		},
		onPullDownRefresh() {
			//下拉刷新
			this.page = 1
			this.sotreData1 = []
			this.keyword = ""
			this.GoodsList({
				type: this.type,
				page: this.page,
				keyword: this.keyword
			})
		},
		onReachBottom() {
			//触底
			if (this.isData.length === 0) {
				this.$u.toast("没有更多啦")
				return
			}
			this.page++
			this.GoodsList({
				type: this.type,
				page: this.page,
				keyword: this.keyword
			})
			console.log(this.sotreData1)
		},
		methods: {
			userPage(e) {
				this.$u.route({
					url: 'pages/user/homePage/homePage',
					params: {
						id: e.user_id
					}
				})
			},
			ImageUrl,
			isBase64,
			time,
			//详情
			details(i) {
				this.$u.route({
					url: "/pages/index/detail/detail",
					params: {
						id: i.id,
						type: 1,
						releaseType: 'news'
					}
				})
			},
			communicates(i) {
				createC2CConversation(i.user.mobile, this)
			},
			communicate(i) {
				if (this.type == 1) {
					//推广
					createC2CConversation(i.user.mobile, this)
				} else if (this.type == 2) {
					//参与竞标
					console.log(this.type)
				}
			},
			//获取货物列表信息
			GoodsList(data) {
				// this.sotreData1 = []
				this.$u.api.collection.getNewsList(data).then(res => {
					this.isData = res
					this.sotreData1.push(...res)
					uni.stopPullDownRefresh()
				})
			},
			search() {
				this.page = 1
				this.sotreData1 = []
				this.GoodsList({
					type: this.type,
					searchKey: this.keyword,
					page: this.page
				})
			}
		},
		computed: {
			toImages() {
				return (src) => {
					return isBase64(src) ? src : IMAGE_URL + src
				}
			},
			storeImages() {
				return (sum, images) => {
					if (!Array.isArray(images)) return images
					return images.length > sum ? images.splice(sum) : images
				}
			},
		}
	}
</script>

<style lang="scss">
	.bidding_news {
		justify-content: center;
		margin-bottom: 31.4rpx;
		width: 90%;
		margin: 0 auto;

		.bidding_card {
			width: 692rpx;
			background: $my-bgColorFFFFFF;
			box-shadow: 3rpx 7rpx 3rpx 0rpx rgba(234, 234, 234, 0.5);
			border-radius: 14rpx;
			overflow: hidden;

			.bidding_user {
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: $my-padding-20;

				//头像大小
				.bidding_user_image {
					padding-left: $my-padding-10;
					height: 50rpx;
					width: 50rpx
				}

				//用户图标
				.bidding_user_icon {
					padding-left: $my-padding-10;
					height: 35rpx;
					width: 35rpx;
				}

				//用户昵称
				.bidding_user_text {
					font-size: 24rpx;
					font-weight: 600;
					color: #0B0B0B;
					padding-left: $my-padding-10;
					line-height: 35rpx;
				}
			}

			//商品的简介
			.biddin_synopsis {
				display: flex;
				flex-direction: column;
				justify-content: flex-start;
				padding: 0 $my-padding-20 $my-padding-20 $my-padding-20;

				.bidding_synopsis_sel {
					padding: 5.23rpx 0 0 0;
					font-size: $my-font-size21;
					font-weight: 400;
					color: #0B0B0B;
					line-height: 70rpx;

					& text:last-child {
						font-weight: 600;
						white-space: nowrap;
						width: calc(100% - 180rpx);
						display: inline-block;
						overflow: hidden;
						text-overflow: ellipsis;
						vertical-align: bottom;
					}
				}
			}

			//商品图片展示区
			.bidding_image {
				padding: $my-padding-20 0 0 $my-padding-20;

				image {
					width: 129.07rpx;
					height: 125.58rpx;
					padding-right: 10.98rpx;
				}
			}

			//地址信息
			.bidding_address {
				padding: 13.6rpx $my-padding-20 10rpx $my-padding-20;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				font-size: $my-font-size21;
				font-weight: 400;
				color: #888888;
				line-height: 30rpx;

				.bidding_ares {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: flex-start;

					.bidding_ares1 {
						display: flex;
						justify-content: flex-start;

						image {
							width: 24.42rpx;
							height: 31.4rpx;
						}
					}
				}
			}
		}
	}

	.search {
		height: 125rpx;
		padding: 34.88rpx;
	}

	.bidding_betwn {
		display: flex;
		justify-content: space-between;
	}

	.page {
		height: 100vh;
	}
</style>